DebugInfo = class()

function DebugInfo:init(updateInterval)
    self.fps = 60
    self.mem = 0
    self.lastTime = ElapsedTime
    self.interval = updateInterval or 1
    self.txt = nil
    self.texts = {}
    self.texts[2] = " fps\nMem:"
    self.texts[4] = " mb\n"
    self.texts[6] = " chunk updated\n"
    self.texts[8] = " chunk To Rebuild\n\nEntityList Count:"
    self.texts[10] = "\nEntityBlockList Count:"
    self.texts[12] = "\n\nPlayerPos:"
    self.texts[14] = " "
    self.texts[16] = " "
    self.texts[18] = "\nBR:"
    self.texts[20] = "\nBiome:"
end

function DebugInfo:draw()
    self.fps = self.fps * 0.9 + 0.1 / (DeltaTime)
    if not GameSetting.ShowDebug then return end
    local txt
    if ElapsedTime - self.lastTime > self.interval then
        local x,y,z = math.floor(player.x),math.floor(player.y),math.floor(player.z)
        local b = player.selectBlock
        self.texts[1] = math.floor(self.fps)
        self.texts[3] = math.ceil(collectgarbage("count") // 1024)
        self.texts[5] = lastSecondChunkUpdated
        self.texts[7] = #worldRenderer.toRebuildChunkList
        self.texts[9] = world.entityList:getSize()
        self.texts[11] = world.entityBlockList:getSize()
        self.texts[13] = x
        self.texts[15] = y
        self.texts[17] = z
        self.texts[19] = world:getBrightness(x,y,z)
        local biome = world.chunkManager:getBiomeAt(x,z)
        if biome then
            self.texts[21] = biome.biomeName
        else
            self.texts[21] = "Nil"
        end
        if b then 
            local sbt = {}
            sbt[1] = "\nSelectBlock:"
            sbt[2] = math.floor(b.x)
            sbt[3] = " "
            sbt[4] = math.floor(b.y)
            sbt[5] = " "
            sbt[6] = math.floor(b.z)
            sbt[7] = " "
            sbt[8] = b.f
            sbt[9] = " "
            sbt[10] = b.block.id 
            sbt[11] = "\nSelectBlock BR:"
            sbt[12] = world:getBrightness(b.x,b.y,b.z)
            self.texts[22] = table.concat(sbt)
        else
            self.texts[22] = nil
        end
        self.txt = table.concat(self.texts)
        self.lastTime = ElapsedTime
    end
    pushStyle()
    font("SourceSansPro-Regular")
    fontSize(18)
    local w,h = textSize(self.txt)
    fill(0, 0, 0, 50)
    noStroke()
    rectMode(CORNER)
    rect(0,HEIGHT - h,w + 5,h)
    fill(255, 255, 255, 255)
    textMode(CORNER)
    text(self.txt,2,HEIGHT - h)
    popStyle()
end